package com.fulu.game.bigdata.realtime.utils

import java.text.SimpleDateFormat
import java.util.{Calendar, Date}

object TimeUtils {

  def isSameDay(startTime: String, endTime: String): Boolean = {
    val startDay = startTime.substring(0, 10)
    val endDay = endTime.substring(0, 10)
    startDay == endDay
  }

  def currentHour(): String = {
    val dateFormat = new SimpleDateFormat("HH")

    dateFormat.format(new Date())
  }

  def subTime(endTime: String, startTime: String): Long = {

    val dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")

    val startDate = dateFormat.parse(startTime)
    val endData = dateFormat.parse(endTime)

    endData.getTime - startDate.getTime
  }

  def nextDay(time: String): String = {
    val dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    val date = dateFormat.parse(time)
    val calendar = Calendar.getInstance();
    calendar.setTime(date)
    calendar.add(Calendar.DATE,1)
    val nextDate = calendar.getTime
    val nextTimeStr = dateFormat.format(nextDate)
    nextTimeStr.substring(0,10) + " 00:00:00"
  }

  def millsOfToday(): Long = {
    val cal = Calendar.getInstance
    cal.set(Calendar.HOUR, 0)
    cal.set(Calendar.MINUTE, 0)
    cal.set(Calendar.SECOND, 0)
    cal.set(Calendar.MILLISECOND, 0)
    cal.getTimeInMillis
  }

}
